<form>
<div class="x-list-title">
<table width="100%" border="0" height="100%">
	<tr>
		<td align="left">
			<h2>Lịch cơ quan ngày</h2>
		</td>
		<td align="right">	
			<div class="x-list-options">	
				<a href="#Calendar/Index/Add" class="x-button">Lịch cá nhân mới</a>
				<a href="#Calendar/Company/Add" class="x-button">Lịch cơ quan mới</a>
			</div>	
		</td>
	</tr>
</table>	
</div>
<div class="calendar-bar-container">
	<div class="calendar-bar">
		<?php $time = $this->get('time');?>
		<?php $pre_date  = date("Y-m-d",strtotime("-1 day",$time));?>
		<?php $next_date = date("Y-m-d",strtotime("+1 day",$time));?>
		<div class="calendar-ctr"><a href="#Calendar/Company?date=<?php _e($pre_date);?><?php if( isset($_GET['department_id'] )) _e('&department_id='.get('department_id')) ?>" class="pre-calendar"></a>
		<a href="#Calendar/Company?date=<?php _e($next_date);?><?php if( isset($_GET['department_id'] )) _e('&department_id='.get('department_id')) ?>" class="next-calendar"></a></div>
		  <?php _e(vn_day($time))?> ngày <?php _e(date("d",$time))?> tháng <?php _e(date("m",$time))?> năm <?php _e(date("Y",$time))?>
		<?php include '_Options.phtml';?>
	</div>
</div>
<?php $posts = $this->get('posts');?>
<table width="100%" class="x-list" cellpadding="0" cellspacing="0">
<tr>
	<th width="100">Thời gian</th>
	<th>Nội dung</th>
	<th width="100">Phòng ban</th>
	<th width="100">Chuẩn bị</th>
	<th width="150">Tham gia</th>
	<th width="100">Địa điểm</th>
	<th width="100">Chủ trì</th>
</tr>
<?php 
	$now = date('d/m/Y',$time) == date('d/m/Y');
?>	
<?php for( $i=0; $i <= 23 ; $i++ ):?>
	<?php $rowspan=0; $html = ""; $is_hidden = true;?>
	<?php foreach( $posts as $k => $a ):?>
	<?php $time_start = strtotime($a['time_start']);
		$time_end = strtotime($a['time_end']);
		$time_now = strtotime("$i:00:00");
				
		$is_current = $now && (((int)date("H")) >= $i ) && (((int)date("H")) < $i+1 )
			? " class='time-current'" :'';
		
		if( $time_start >= $time_now && strtotime(($i+1).":00:00") > $time_start ):?>
		<?php
			
			$time = date('H:i',strtotime($a['time_start']))." &#187; ".date('H:i',strtotime($a['time_end']));
			$tooltip ="<div class='x-toolbox'>
				<div class='event-quick-box'>
				<div style='border-bottom:1px solid #ddd;padding:0px 0px 5px 0px'>
				<big><b>{$a['title']}</b></big><br/>
				<i>$time</i><br/>
				</div><div style='padding:5px 0px'>
				".short_title(strip_tags($a['content']),300)."
				</div></div>
			</div>";
			
			if( $rowspan  == 0 ){
				$html .="<td><div class='calendar-post'>
						<a class='x-tooltip' href='#Calendar/Company/View?ID={$a['ID']}'>&#187; ".short_title($a['title'],40)."	$tooltip</a> ( $time )
					</div></td>
					<td align='center'><a href='#Calendar/Company?department_id={$a['department_id']}'>{$a['department_title']}</a></td>
					<td>{$a['tools']}</td>
					<td>{$a['guests']}</td>
					<td align='center'>{$a['place']}</td>
					<td align='center'>{$a['chairman']}</td>
				</tr>";			
				$rowspan++;
			}else{
				$html .="<tr>
					<td><div class='calendar-post'>
						<a class='x-tooltip' href='#Calendar/Company/View?ID={$a['ID']}'>&#187; {$a['title']}	$tooltip</a> ( $time )
					</div></td>
					<td align='center'><a href='#Calendar/Company?department_id={$a['department_id']}'>{$a['department_title']}</a></td>
					<td>{$a['tools']}</td>
					<td>{$a['guests']}</td>
					<td align='center'>{$a['place']}</td>
					<td align='center'>{$a['chairman']}</td>					
				</tr>";			
				$rowspan++;			
			}	
		?>		
	<?php endif;?>
	<?php endforeach;?>
	<?php 
		if( $rowspan  == 0 ){
			$is_hidden =false;
			$html .="<td></td><td></td><td></td><td></td><td></td><td></td></tr>";		
		}	
	?>
	<?php if( $i < 6 ):?>	
	<tr class="cday-outtime<?php _e($is_hidden ? "":" cday-hide");?>">
		<td align="center" width="100"<?php _e($rowspan > 1 ? " rowspan='$rowspan'":'');?>>
			<span<?php _e($is_current)?>><?php _e(date("H:i",strtotime("$i:00:00")));?></span>
		</td>
		<?php _e($html);?>
	<?php endif;?>
	<?php if( $i <= 18 && $i >= 6 ):?>	
	<tr class="cday-intime">
		<td align="center" width="100"<?php _e($rowspan > 1 ? " rowspan='$rowspan'":'');?>>
			<span<?php _e($is_current)?>><?php _e(date("H:i",strtotime("$i:00:00")));?></span>
		</td>
		<?php _e($html);?>
	<?php endif;?>
	<?php if( $i > 18 ):?>	
	<tr class="cday-outtime<?php _e($is_hidden ? "":" cday-hide");?>">
		<td align="center" width="100"<?php _e($rowspan > 1 ? " rowspan='$rowspan'":'');?>>
			<span<?php _e($is_current)?>><?php _e(date("H:i",strtotime("$i:00:00")));?></span>
		</td>
		<?php _e($html);?>
	<?php endif;?>
<?php endfor;?>
</table>
<div align="right" class="calendar-expand">
	<a onclick="calendar_expand_day(this)" >[mở rộng]</a>
</div>